//
// Created by liushuai on 2021/1/5.
//

#include "convert.h"
std::string convert(std::string s, int numRows)
{
    if (numRows == 1)
        return s;
    int sSize = int(s.size());
    int storeSize = std::min(sSize, numRows);
    std::string result;
    std::vector<std::string> store(storeSize);
    int loc_index = 0;
    //初始有一次更改change值，因此初始值为false
    bool change = false;
    for (int index = 0; index < sSize; index++)
    {
        store[loc_index].push_back(s[index]);
        if (loc_index == numRows - 1 || loc_index == 0)
            change = !change;
        loc_index += change ? 1 : -1;
    }

    for (int index = 0; index < storeSize; index++)
        result = result + store[index];
    return result;
}
